{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def test():\n",
      "    test = 10\n",
      "    return test\n",
      "\n",
      "print test()\n",
      "print test()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "10\n",
        "10\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "class A(object):\n",
      "    def __init__(self):\n",
      "        print(\"A.__init__\")\n",
      "        self.foo()\n",
      "    \n",
      "    def foo(self):\n",
      "        print(\"A.foo()\")\n",
      "        \n",
      "class B(A):\n",
      "    def __init__(self):\n",
      "        print(\"B.__init__\")\n",
      "        super(B, self).__init__()\n",
      "        \n",
      "class C(B):\n",
      "    def __init__(self):\n",
      "        print(\"C.__init__\")\n",
      "        super(C, self).__init__()\n",
      "        \n",
      "    def foo(self):\n",
      "        print(\"C.foo()\")\n",
      "        \n",
      "a = A()\n",
      "print(\"---\")\n",
      "b = B()\n",
      "print(\"---\")\n",
      "c = C()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A.__init__\n",
        "A.foo()\n",
        "---\n",
        "B.__init__\n",
        "A.__init__\n",
        "A.foo()\n",
        "---\n",
        "C.__init__\n",
        "B.__init__\n",
        "A.__init__\n",
        "C.foo()\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import print_function\n",
      "\n",
      "class A(object):\n",
      "    def __init__(self):\n",
      "        self.foo()\n",
      "    \n",
      "    def foo(self):\n",
      "        print(\"A.foo()\")\n",
      "        \n",
      "class B(object):\n",
      "    def __init__(self):\n",
      "        print('B.__init__')\n",
      "        \n",
      "    def bar(self):\n",
      "        print(\"B.bar()\")\n",
      "        \n",
      "class C(A,B):\n",
      "#    def __init__(self):\n",
      "#        super(C, self).__init__()\n",
      "        \n",
      "    def foo(self):\n",
      "        print(\"C.foo()\")\n",
      "        \n",
      "a = A()\n",
      "print(\"-----------\")\n",
      "b = B()\n",
      "print(\"-----------\")\n",
      "c = C()\n",
      "c.bar()\n",
      "print(\"isinstance(c, A)=\", isinstance(c, A), \"\\n\",\n",
      "      \"isinstance(c, B)=\", isinstance(c, B), \"\\n\",\n",
      "      \"isinstance(c, C)=\", isinstance(c, C), \"\\n\",\n",
      "      \"isinstance(b, C)=\", isinstance(b, C), sep=\"\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A.foo()\n",
        "-----------\n",
        "B.__init__\n",
        "-----------\n",
        "C.foo()\n",
        "B.bar()\n",
        "isinstance(c, A)=True\n",
        "isinstance(c, B)=True\n",
        "isinstance(c, C)=True\n",
        "isinstance(b, C)=False\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "class Blah(object):\n",
      "    a = 1\n",
      "\n",
      "blah = Blah()\n",
      "print(blah.a)\n",
      "\n",
      "def args(**kwargs):\n",
      "    for key, value in kwargs.iteritems():\n",
      "        blah.__setattr__(key, value)\n",
      "\n",
      "args(a=5)\n",
      "print(blah.a)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1\n",
        "5\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Object `blah` not found.\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}